require(['layer'], function(layer){

	// 微调价格
	trimPrice = function(){
		$('.trim-btn').click(function() {
			var self = $(this),
			url       = self.attr("data-url"),
			order_id  = self.attr("order-id"),
			old_value = self.attr("old-value");

			layer.prompt({
			  formType: 0,
			  value: old_value,
			  title: '请输入微调值',
			  maxlength: 8,
			}, function(value, index, elem){
				var patt = /^(-?\d+)(\.\d+)?$/;
				if(!patt.test(value)) {
					layer.alert('请输入正负浮点数',{icon: 5});
					return false;
				}

				var trimData = {order_id:order_id,fine_tune_price:value};

				// 编辑微调值
		  		$.post(url, trimData, function(json){
		  			if(json.code){
		  				layer.alert(json.msg,{icon: 1});
		  				// layer.close(index);
		  				pageReload(1000);
		  			} else {
		  				layer.alert(json.msg,{icon: 2});
		  			}
		  		});

			});


		});
	}


	// 编辑发货信息
	editDeliver = function(){
		$('.edit-btn').click(function() {
			var self = $(this),
			url       = self.attr("data-url"),
			proc_url  = self.attr("proc-url"),
			order_id  = self.attr("order-id");

			layer.open({
			    type: 2,
			    title: '编辑发货单信息',
			    shade: 0.5,
			    scrollbar : false,
			    area : ['80%','40%'],
			    content: url+'?order_id='+order_id,
			    btn: ['修改','关闭'],
			    yes : function(index, layerDom){
					var childBody = layer.getChildFrame('body', index);
					//iframe窗口
					var iframeWin = window[layerDom.find('iframe')[0]['name']];
					//调用子页面方法
					var editData = $(childBody).find('.ajax-form').serialize();
					//发布
					$.post(proc_url, editData, function(json){
						if(json.code){
							layer.alert(json.msg,{icon: 1});
							layer.close(index);
							pageReload(1000);
						} else {
							layer.alert(json.msg,{icon: 2});
						}
					});
				}
			});

		});
	}

	// 微调价格
	trimPrice();

	// 编辑发货信息
	editDeliver();

});

